<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="/css/common.css" />
		<link rel="stylesheet" type="text/css" href="/js/flatpickr.min.css" />
		<link rel="stylesheet" type="text/css" href="/bootstrap-3.3.7/css/bootstrap.min.css" />
		<link rel="stylesheet" type="text/css" href="/dialog/css/dialog.css" />
		<link rel="stylesheet" type="text/css" href="/css/font-awesome.css" />

        <script src="/js/jquery-1.9.1.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="/js/google-maps.js" type="text/javascript" charset="utf-8"></script>
        <script src="/js/jquery.validate.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="/js/messages_zh.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="/js/common.js"></script>
        <script src="/js/jquery.form.js"></script>
        <script src="/dialog/js/dialog.js"></script>
        <script src="/js/flatpickr.js"></script>

		<script type="text/javascript" charset="utf-8">
            //初始化侧边栏
            $(function() {
                $(".vertical-nav").verticalnav({
                    speed: 400,
                    align: "left"
                });
            });

			function edit1(id){
				$.ajax({
					type:'post',
					url:'/admin/carInfo/edit',
					data:{
					    id : id
					},
					success:function (data) {
                        $.dialog({
                            type: 'confirm',
                            titleText: '更改数据',
                            contentHtml: '<form id="updateform" action="/admin/carInfo/updateByDialog" method="post"><ul class="changePage500">'+
                            '<li>' +
							'<label class="labelBeforinput">汽车编号</label>' +
							'<input name="carId" disabled class="bigInputtext" type="text" value="' +data.carId+ '" />' +
							'</li>'+
                            '<li>' +
							'<label class="labelBeforinput">企业编号</label>' +
							'<input name="compId" disabled class="bigInputtext" type="text" value="' +data.compId+ '" />' +
							'</li>'+
                            '<li>' +
							'<label class="labelBeforinput">车牌号</label>' +
							'<input name="licenseNumber" require class="bigInputtext" type="text" value="' +data.licenseNumber+ '" />' +
							'</li>'+
                            '<li>' +
							'<label class="labelBeforinput">汽车品牌</label>' +
							'<input name="carBrand" require class="bigInputtext" type="text" value="' +data.carBrand+ '" />' +
							'</li>'+
                            '<li>' +
							'<label class="labelBeforinput">备注</label>' +
							'<input name="remark" require class="bigInputtext" type="text" value="' +data.remark+ '" />' +
							'</li>'+
                            '<li>' +
							'<label class="labelBeforinput">使用状态</label>' +
							'<input name="status" require class="bigInputtext" type="text" value="' +data.status+ '" />' +
							'</li></ul>'+
                            '</form>',
                            ok: "保存提交",
                            cancel: "取消",
							onShow:function () {
                                $("#updateform").validate({
                                    rules:{
                                        licenseNumber:"number",
                                        carBrand:{
                                            required:true,
                                            minlength:3,
                                            maxlength:8
                                        },
                                        remark:"required",
										status:"required"
                                    },
                                    message:{
                                        licenseNumber:"请输入数字",
                                        carBrand:{
                                            required:"此项必填！！",
                                            minlength:"最小长度为3",
                                            maxlegth:"最大长度为8"
                                        },
                                        remark:"此项必填！！",
                                        status:"此项必填！！"

                                    }
                                });
                            },
                            onClickOk:function(){
                                $("#updateform").submit();
							}
                        });
                    }
				});
			}

			/*异步删除*/
			function delete1(id) {
				$.ajax({
					type:'post',
					url:'delete',
					data:{
					    id : id
					},
                    success:function(data) {
					    if(data.code == 0){
                            document.location.reload();
						}else{
					        alert("删除失败");
						}
                    }
                });
            }

            /*异步模糊查询*/
            /* 此处可以不用字符串拼接*/
            function inquery(){
				var licenseNumber = $("#licenseNumber").val();
				var compName = $('#compName').val();
				$.ajax({
					type:'POST',
					url:'inquiry',
					data:{
					    licenseNumber : licenseNumber,
						compName : compName
					},
					success:function (json) {
						var vos = json.data.carInfoVOs;//获取返回的所有VO类集合
                    	var tbody = $("#tbody");
                    	tbody.children('tr').remove();
                    	$.each(vos , function (n,vo) {
							var data1 = '<tr><th width="20"><input type="checkbox" value="'+vo.carInfo.carId+'"/></th>'+
                                    '<th width="100">'+vo.carInfo.licenseNumber+'</th>'+
                                    '<th width="100">'+vo.carInfo.carBrand+'</th>'+
                                    '<th width="50">'+vo.carInfo.compId+'</th>'+
                                    '<th width="100">'+vo.companyInfo.compname+'</th>'+
                                    '<th width="100">'+vo.carInfo.status+'</th>'+
                                    '<th width="100">'+vo.carInfo.remark+'</th>'+
                                    '<th width="70"><input type="button" onclick="JavaScript:edit1('+vo.carInfo.carId+')"  value="编辑"/>'+
                                    '<input type="button" onclick="JavaScript:if(confirm(&apos;是否删除&apos;)){ delete1('+vo.carInfo.carId+')}" value="删除"/>'+
                                    '</th></tr>';
							tbody.append(data1);
                        });
					}
				});
            }

            //全选、全不选
			function selectAll() {
				if ($("#allSelect").is(":checked")) {
					$("input[name='isCheck']").prop("checked",true);
				} else {
					$("input[name='isCheck']").prop("checked",false);
				}
			}

			//删除多项
			function deleteByids() {
				var option = $("input[name='isCheck']:checked");
				var ids = "";
				for (i = 0; i< option.length;i++){
					if(i == 0){
						ids += option[i].value;
					}else{
						ids += "," + option[i].value;
					}
				}
				$.dialog({
					type: 'confirm',
					contentHtml: '<p style:"magrin:0 auto">确认删除？</p>',
					onClickOk: function() {
						$.ajax({
							url: "deleteByids",
							data: {
								'ids': ids
							},
							error: function(XMLHttpRequest, textStatus, errorThrown) {
								//弹失败框
								$.dialog({
									type: 'info',
									contentHtml: '<img class="info-icon" src="dialog/images/icon/fail.png" alt="删除失败" /><p class="info-text">删除失败</p>',
									autoClose: 1000
								});
							},
							success: function() {
								//弹成功框
								$.dialog({
									type: 'info',
									contentHtml: '<img class="info-icon" src="dialog/images/icon/success.png" alt="删除成功" /><p class="info-text">删除成功</p>',
									autoClose: 1000
								});
								setTimeout("window.location.reload();",1000);
							}
						});
					}
				});
			}
        </script>
	</head>
	<body>
		<!--顶部导航 -->
		<nav class="topNavItemBox">
			<div id="ItemBox">
				<div class="title">肉品溯源管理系统</div>
			</div>
		</nav>
		<!-- 左侧导航 -->
		<#include "left.ftl" />

		<div class="page_main">
			<h3>车辆管理</h3><span class="add_link"><a href="add">新增车辆></a></span>
			<div class="page_content">
				<h4>车辆查询</h4>
				<br />

				<form action="/admin/carInfo/list" method="post">
					<label>车牌号</label>
					<input type="text" id="licenseNumber" name="licenseNumber" value="${licenseNumber}" class="commonInputtext" /><span></span>
					<label>公司名</label>
					<input type="text" id="compName" name="compName" value="${compName}" class="commonInputtext" />
					<input type="submit" value="查询" <#--onclick="inquery()"--> style="display: inline-block; margin-left: 50px;" />
                </form>

				<div>
					<table id="carsInfo_table" class="table" width="100%">
						<thead>
							<tr>
								<th width="20"><input id="allSelect" onclick="selectAll()" type="checkbox" /></th>
								<th width="100">车牌号</th>
								<th width="100">汽车品牌</th>
								<th width="50">公司编号</th>
                                <th width="100">所属公司名称</th>
								<th width="100">使用状态</th>
								<th width="100">评论</th>
								<th width="50">操作</th>
							</tr>
						</thead>
						<tbody id="tbody">
							<#list page.list as carInfoVO>
								<#--<tr --id="no_data">-->
								<tr>
                                    <th width="20"><input name="isCheck" type="checkbox" value="${carInfoVO.carInfo.carId}"/></th>
                                    <th width="100">${carInfoVO.carInfo.licenseNumber}</th>
                                    <th width="100">${carInfoVO.carInfo.carBrand}</th>
                                    <th width="50">${carInfoVO.carInfo.compId}</th>
                                    <th width="100">${carInfoVO.companyInfo.compname}</th>
                                    <th width="100">${carInfoVO.carInfo.status}</th>
                                    <th width="100">${carInfoVO.carInfo.remark}</th>
                                    <th width="70">
										<input type="button" onclick="edit1(${carInfoVO.carInfo.carId})"  value="编辑"/>
										<input type="button" onclick="JavaScript:if(confirm('是否删除')){ delete1(${carInfoVO.carInfo.carId})}" value="删除"/>
									</th>
								</tr>
							</#list>
						</tbody>
					</table>
				</div>
                <input type="button" id="delete" onclick="deleteByids()" value="删除所选">
				<!-- <input type="button" id="deleteAllchoice" value="删除所选"> -->
				<div id="barcon" name="barcon" style="margin-left: 200px;font-size:10px"></div>
			</div>
			<div class="footer">
				<div class="footer_lineone">
					<span id="logo"></span>肉品溯源管理系统 
					<span class="footer_lineoneSpan"><a href="aboutus.html">关于我们</a></span>
					<span class="footer_lineoneSpan"><a target="_blank" href="http://www.cfsiw.com/">食品安全信息</a></span> 
					<span class="footer_lineoneSpan"><a href="suggestionAdd.ftl">联系我们</a></span>
				</div>
				<div class="footer_linetwo">
					 &copy;2017广东技术师范学院
				</div>
			</div>
		</div>
	</body>
</html>